package com.umeox.watch.moto.apiclient.http.callback;

import android.os.Handler;
import android.os.Looper;

import com.umeox.watch.moto.apiclient.http.request.WaasRequest;
import com.umeox.watch.moto.apiclient.http.response.WaasResponse;


public class UIThreadCallback implements WaasCallback {
    private WaasCallback callback;
    private Handler handler = new Handler(Looper.getMainLooper());

    public UIThreadCallback(WaasCallback callback) {
        this.callback = callback;
    }

    @Override
    public void onFailure(final WaasRequest request, final Exception e) {
        if (this.callback != null) {
            this.handler.post(new Runnable() {
                @Override
                public void run() {
                    UIThreadCallback.this.callback.onFailure(request, e);
                }
            });
        }
    }

    @Override
    public void onResponse(final WaasRequest request, final WaasResponse response) {
        if (this.callback != null) {
            this.handler.post(new Runnable() {
                @Override
                public void run() {
                    UIThreadCallback.this.callback.onResponse(request, response);
                }
            });
        }
    }
}
